<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of taskModelClass
 *
 * @author nstevens
 */
//require_once "model/subtaskModelClass.php";
require_once "controller/subtaskControllerClass.php";
require_once 'model/commonModel.php';

class taskModelClass extends commonModel {

    public $projectID, $projectStatus, $description, $duration, $fy;
    //2D subtask array
    public $subtasks, $notes, $requirements, $parameters;

    public function __construct() {
        
    }

    public function init($row) {
        $this->title = $row['title'];
        $this->wbsID = $row['wbsID'];
        $this->wbsString = getWbsString($this->wbsID);
        $this->startDate = $row['startDate'];
        $this->endDate = $row['endDate'];
        $this->ID = $row['taskID'];
        $this->status = $row['status'];
        $this->duration = $row['duration'];
        $this->description = $row['description'];
        $this->proposedCost = $row['proposedCost'];
        $this->actualCost = $row['actualCost'];
        $this->projectID = $row['projectID'];
        $this->projectStatus = getFieldGivenAnID('project', "projectID", $this->projectID, "status");
        $this->projectStartDate = getFieldGivenAnID('project', "projectID", $this->projectID, "startDate");
        $this->projectEndDate = getFieldGivenAnID('project', "projectID", $this->projectID, "endDate");
        $this->fy = getFieldGivenAnID('project', "projectID", $this->projectID, "fy");
        $this->notes = $this->getAllNotes();
        $this->requirements = $this->getRequirements();
        $this->parameters = $this->getParameters();
        $this->subtasks = $this->getTaskSubtasks();
    }

    //DATA**********************************************************************
    function getTaskSubtask($subtaskID) {
        if (!$this->subtasks) {
            $this->subtasks = $this->getTaskSubtasks();
        }
        foreach ($this->subtasks as $subtask) {
            if ($subtask->ID === $subtaskID) {
                return $subtask;
            }
        }
        return NULL;
    }

    function getRequirements() {
        $array = array();
        $result = executeSelect("SELECT r.reqID FROM requirement r, taskreqmap tm WHERE r.reqID=tm.reqID AND tm.taskID=$this->ID");
        if ($result) {
            while ($row = mysqli_fetch_array($result)) {
                array_push($array, $row['reqID']);
            }
            return $array;
        }
        return NULL;
    }

    function getParameters() {
        $array = array();
        $result = executeSelect("SELECT p.parameterID FROM parameter p, taskparammap tp WHERE p.parameterID=tp.paramID AND tp.taskID=$this->ID");
        if ($result) {
            while ($row = mysqli_fetch_array($result)) {
                array_push($array, $row['parameterID']);
            }
            return $array;
        }
        return NULL;
    }

    //HTML**********************************************************************
    public function getTaskDetailsPage() {
        //header
        $output = $this->getBasicHeader("Task Details");
        $output .= '<a href="mainPage.php?request=project&projectId=' . $this->projectID . '&action=viewProjectDetailsRequest">Back to Project</a>';
        //display any flags
        if (isset($_GET['update'])) {
            $output .= $this->getFlagUnorderedList($_GET['update']);
        }
        //task details
        $output .= $this->getTaskDetailsForm();
        $output .= "<br><br><hr><br>";
        //subtasks
        $output .= $this->getSubTaskSummaryForm();
        $output .= "<br><br><hr><br>";
        if (isProjectInApprovedState($this->projectStatus) && !(strcmp($this->projectStatus, 'submitComplete') === 0)) {
            $output .= $this->getFinancialsCurrentYearTable();
            $output .= '<br>' . $this->getStatusColorLegendTable();
            $output .= "<br><br><hr><br>";
        }
        //task notes
        if (!isProjectInApprovedState($this->projectStatus) || strcmp($this->projectStatus, 'submitComplete') === 0) {
            $output .= $this->getNotesFormFromObject($this->getNotes('Feedback'), NULL, "Feedback");
        }
        if (!isPI()) {
            $output .= $this->getNotesFormFromObject($this->getNotes('Reviewer Notes'), NULL, "Reviewer Notes");
        }
        $output .= $this->getNotesFormFromObject($this->getNotes('PI Notes'), NULL, "PI Notes");
        $output .= "<br><br><hr><br>";

        //empty task notes form
        //$output .= $this->getNotesForm($this->wbsID, "PI Notes");
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getEditTaskPage() {
        $output = "";
        $output .= $this->getBasicHeader("Edit Task");
        //$output .= $this->getEditTaskForm();
        $output .= commonModel::getTaskForm($this);
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    public function getNewSubtaskPage() {
        $start = $_POST['projectStartDate'];
        $end = $_POST['projectEndDate'];
        $output = subtaskModelClass::getNewSubtaskHeader();
        $output = $this->getBasicHeader("New Subtask", false, false, $start, $end);
        $output .= commonModel::getSubtaskForm();
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        return $output;
    }

    function getNewSubtaskFormQuarterly() {
        $output = "";
        $reqDropdownString = "hi";
        $commentsTextFieldString = getFormInputElementText("text", "commentsTextField", "98%", NULL, NULL, 'commentsTextField');
        $depAddButtonText = getFormInputElementText("button", "depAddButton", "98%", "Add Dependency", "addDependencyRow()");
        //if we are editing the form then get all of the values

        $caption = '<caption>New Subtask</caption>';
        $dependencyDropdownString = getDependencyDropdownText($this->projectID);
        //$reqDropdownString = getGenericDropdownMenuText(getRequirements($this->fy, true), "reqDropdown", NULL, false, "getParametersFromReq(this.value)", "reqDropdown", NULL, NULL, NULL, true);
        $reqDropdownString = getGenericDropdownMenuText(getRequirements($this->fy, true), "reqDropdown", NULL, false, NULL, "reqDropdown", NULL, NULL, NULL, true);
        $categoryDropdownString = getDropDownMenuText(getSubtaskCatergoryArray(), "dropdownCategory");
        $deliverableTextfieldString = getFormInputElementText("text", "deliverableTextField", "93%");
        $parameterDropdownString = getGenericDropdownMenuText(executeSelect("SELECT * FROM parameter ORDER by name"), "dropdownParameter", "85%", false);
        $titleString = getFormInputElementText("text", 'titleTextField', '95%');
        $descriptionTextFieldString = getFormInputElementText("text", 'descriptionTextField', '95%', NULL, NULL, 'descriptionTextfield');
        $startDateTextFieldString = getFormInputElementText("text", "startDateTextField", '85%', NULL, NULL, "from");
        $endDateTextFieldString = getFormInputElementText("text", "endDateTextField", '85%', NULL, NULL, "to");
        //$durationTextFieldString = getFormInputElementText("text", "durationTextField", '85%', NULL, NULL, 'duration');
        //$costTextFieldString = getFormInputElementText("text", "costTextField", '85%', NULL, "getRate()", 'cost');
        $rate = "";
        $submitButtonString = getFormInputElementText("submit", "submit", NULL, "Create Subtask");

        $output .= $this->getRequiredFieldText();
        $output .= getFormLinePostWithOnSubmit("createSubtaskForm", "mainPage.php?request=task&action=processNewSubtask&taskId=$this->ID&projectId=$this->projectID", " validateSubtask(this)");
        //getFormLinePostWithOnSubmit("createSubtaskForm", "subtaskController.php");
        //getStartFormLinePostWithOnSubmit("createSubtaskForm", "test.php", " validateSubtask(this)");
        //Table Start***************************************************************
        $output .= '<table class="width100" cellspacing="1">';
        $colWidth = 100 / 10;
        $output .= '<col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%"><col width="' . $colWidth . '%">';
        $output .= $caption;
        $output .= ' <tr class="row-category"><td class="col-2" colspan="10">Subtask Description</td></tr>';

        //Section 1 Title, Description**********************************************
        $output .= ' <tr class ="fieldLabel">';
        $output .= '     <td colspan="3">Title</td>';
        $output .= '     <td colspan="7">Description</td>';
        $output .= ' </tr>';

        $output .= ' <tr class="lightGray">';
        $output .= '     <td class="required" colspan="3">';
        $output .= $titleString;
        $output .= '     *</td>';
        $output .= '     <td class="required" colspan="7">';
        $output .= $descriptionTextFieldString;
        $output .= '     *</td>';
        $output .= ' </tr>';

        //Section 2  Req, Parameter, Category, Deliverable**************************
        $output .= ' <tr class ="fieldLabel">';
        $output .= '     <td colspan="10">Requirement (Ordered By Priority)</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="lightGray">';
        $output .= '     <td class="required" colspan="10">';
        $output .= $reqDropdownString;
        $output .= '     *</td>';
        $output .= ' </tr>';

        $output .= ' <tr class ="fieldLabel">';
        $output .= '     <td colspan="3">Parameter</td>';
        $output .= '     <td colspan="2">Category</td>';
        $output .= '     <td colspan="5">Deliverable</td>';
        $output .= ' </tr>';
        $output .= ' <tr class="lightGray">';
        $output .= '     <td class="required" id="edrBox" colspan="3">';
        $output .= $parameterDropdownString;
        $output .= '     *</td>';
        $output .= '     <td class="required" colspan="2">';
        $output .= $categoryDropdownString;
        $output .= '     *</td>';
        $output .= '     <td  class="required" colspan="5">';
        $output .= $deliverableTextfieldString;
        $output .= '     *</td>';
        $output .= ' </tr>';

        //Section 3 start, end, duration, cost**************************************
        $output .= ' <tr class="row-category"><td class="col-2" colspan="10">Subtask Labor</td></tr>';
        $output .= ' <tr class ="fieldLabel">';
        $output .= '     <td>Start Date</td>';
        $output .= '     <td>End Date</td>';
        $output .= '     <td>Q1 Cost</td>';
        $output .= '     <td>Q2 Cost</td>';
        $output .= '     <td>Q3 Cost</td>';
        $output .= '     <td>Q4 Cost</td>';
        $output .= '     <td>Q1 Hours</td>';
        $output .= '     <td>Q2 Hours</td>';
        $output .= '     <td>Q3 Hours</td>';
        $output .= '     <td>Q4 Hours</td>';
        $output .= ' </tr>';

        $output .= ' <tr class="lightGray">';
        $output .= $this->getTD($startDateTextFieldString);
        $output .= $this->getTD($endDateTextFieldString);
        $output .= $this->getTD(getFormInputElement('text', 'q1Cost', "97%"));
        $output .= $this->getTD(getFormInputElement('text', 'q2Cost', "97%"));
        $output .= $this->getTD(getFormInputElement('text', 'q3Cost', "97%"));
        $output .= $this->getTD(getFormInputElement('text', 'q4Cost', "97%"));
        $output .= $this->getTD(getFormInputElement('text', 'q1Hours', "97%"));
        $output .= $this->getTD(getFormInputElement('text', 'q2Hours', "97%"));
        $output .= $this->getTD(getFormInputElement('text', 'q3Hours', "97%"));
        $output .= $this->getTD(getFormInputElement('text', 'q4Hours', "97%"));
        $output .= ' </tr>';

        //Section 4 Dependencies****************************************************
        $output .= ' <tr class="row-category"><td class="col-2" colspan="10">Subtask Dependencies</td></tr>';
        $output .= ' <tr class ="fieldLabel">';
        $output .= '     <td colspan="2">Select a subtask this subtask is dependent on</td>';
        $output .= '     <td colspan="3">Comments</td>';
        $output .= '     <td colspan="5"></td>';
        $output .= ' </tr>';

        $output .= ' <tr>';
        $output .= '     <td class="col-2" colspan="2">';
        $output .= $dependencyDropdownString;
        $output .= '     </td>';
        $output .= '     <td class="col-2" colspan="3">';
        $output .= $commentsTextFieldString;
        $output .= '     </td>';
        $output .= '     <td  class="col-2" colspan="2">';
        $output .= $depAddButtonText;
        $output .= '     </td>';
        $output .= '     <td class="col-2" colspan="3"></td>';
        $output .= ' </tr>';
        $output .= '<tr>';
        $output .= '     <td class="col-2" colspan="8">';
        $stObject = new subtaskModelClass();
        $output .= $stObject->getDependencyTable();
        $output .= '</td>';
        $output .= '     <td class="col-2" colspan="2"></td>';
        $output .= ' </tr>';
        //submit button
        $output .= ' <tr class ="fieldLabel">';
        $output .= '     <td colspan="6">';
        $output .= $submitButtonString;
        $output .= '     </td>';
        $output .= '     <td colspan="4">';
        $output .= '      <input type="hidden" name="projectID" value="' . $this->projectID . '">';
        $output .= '      <input type="hidden" name="taskID" value="' . $this->ID . '">';
        $output .= '      <input type="hidden" name="projectStartDate" value="' . $this->projectStartDate . '">';
        $output .= '      <input type="hidden" name="projectEndDate" value="' . $this->projectEndDate . '">';
        $output .= getHiddenField("submissionType", "create");
        $output .= '     </td>';
        $output .= ' </tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    /**
     * Gets the html for a sub task summary form with an "Add Subtask" button allowing the user to add a subtask to a task
     * @param type $result
     * @param type $taskId
     */
    function getSubTaskSummaryForm() {
        $output = "";
        $output .= getFormLinePost("singleProjectForm", "mainPage.php?request=task&action=proposeNewSubtaskRequest&taskId=$this->ID&projectId=$this->projectID");
        $output .= $this->getSubtasksSummaryTable();
        $output .= ' <tr class ="fieldLabel">';
        if (strcmp(getUserRole(), "pi") === 0) {
            if (!isProjectInApprovedState(getStatus('project', $this->projectID))) {
                $output .= ' <td colspan="9">';
                $output .= getFormInputElement("submit", "submit", NULL, "Add Subtask", NULL, NULL, getTooltip('addSubtaskButton'));
                $output .= ' </td>';
            }
        }
        $output .= '      <input type="hidden" name="taskId" value="' . $this->ID . '">';
        $output .= '      <input type="hidden" name="projectID" value="' . $this->projectID . '">';
        $output .= '      <input type="hidden" name="projectStartDate" value="' . $this->projectStartDate . '">';
        $output .= '      <input type="hidden" name="projectEndDate" value="' . $this->projectEndDate . '">';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    /**
     * Gets the html table of the subtasks contained in the given result resource.
     * @param type $result the result resource related to a unique taskID from the db (contains 1 or more rows)
     */
    function getSubtasksSummaryTable() {
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Sub Tasks</caption>';
        $output .= ' <tr class ="header">';
        $output .= '     <td>WBS</td>';
        $output .= '     <td>Title</td>';
        $output .= '     <td>Requirement</td>';
        $output .= '     <td>Parameter</td>';
        $output .= '     <td>Effort (Hours)</td>';
        $output .= '     <td>Start Date</td>';
        $output .= '     <td>End Date</td>';
        $output .= '     <td>Proposed Cost ($K)</td>';
        $output .= '     <td>Status</td>';
        $output .= ' </tr>';
        foreach ($this->subtasks as $subtask) {
            $statusBGcolor = getStatusBackgroundColor($subtask->status, 'task');

            $output .= ' <tr class="field">';
            $output .= ' <td>';
            $output .= '<a class="black" href="mainPage.php?request=subtask&action=viewSubtaskDetailsRequest&subtaskId=' . $subtask->ID . '">' . $subtask->wbsString . '</a>';
            //$output .= '<a class="black" href="subtaskController.php?projectId=' . $this->projectID . '&taskId=' . $this->ID . '&subtaskId=' . $subtask->ID . '&start=' . $this->projectStartDate . '&end=' . $this->projectEndDate . '">' . $this->wbsString . '</a>';
            $output .= ' </td>';
            $output .= ' <td>' . $subtask->title . '</td>';
            //echo ' <td>' . $description . ' </td>';
            $output .= ' <td>';
            $output .= getRequirementNameFromID($subtask->reqID);
            $output .= ' </td>';
            $output .= ' <td>';
            $output .= getParameterNameFromID($subtask->parameterID);
            $output .= ' </td>';
            $output .= ' <td>' . $subtask->duration . '</td>';
            $output .= ' <td>' . $subtask->startDate . '</td>';
            $output .= ' <td>' . $subtask->endDate . '</td>';
            $output .= ' <td>' . $subtask->proposedCost . '</td>';
            $output .= " <td bgcolor = \"$statusBGcolor\">$subtask->status</td>";
            $output .= ' </tr>';
        }
        return $output;
    }

    public function getTaskDetailsHeader() {
        $output = "";
        $output .= getNewHtmlUpToMeta();
        $output .= getJavascriptFileLine("js/populateDropdown.js");
        $output .= getJavascriptFileLine("js/addRowToTable.js");
        $output .= getMantisCSSLine();
        $output .= getCSSFileLine("http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css");
        $output .= getJavascriptFileLine("http://code.jquery.com/jquery-1.9.1.js");
        $output .= getJavascriptFileLine("http://code.jquery.com/ui/1.10.3/jquery-ui.js");
        $output .= ' <script> $(function() { $( "#datepicker" ).datepicker(); $( "#datepicker2" ).datepicker(); }); </script>';
        $output .= getTitle("Task Details");
        $output .= getCloseTag("head");
        $output .= getOpenTag("body");
        $output .= getLogoLine();
        $output .= getLoggedInAsLine();
        $output .= getMenuBar(getUserRole());
        $output .= '<br>';
        $output .= '<a href="mainPage.php?request=project&projectId=' . $this->projectID . '&action=viewProjectDetailsRequest">Back to Project</a>';
        $output .= '<a href="projectController.php?projectId=' . $projectID . '">Back to Project</a>';
        $output .= '<br>';

        return $output;
    }

    function getTaskDetailsForm() {
        $output = "";
        $output .= getFormLinePost("taskDetailsForm", "mainPage.php?request=task&action=processExistingTaskRequest&taskId=$this->ID&projectId=$this->projectID");
        $output .= $this->getTaskDetailsTable(false);
        $output .= $this->getTaskSummaryButtonRow();
        $output .= '<tr class ="fieldLabel"><td colspan="10"><input type="hidden" name="projectID" value="' . $this->projectID . '"></td></tr>';
        $output .= getCloseTag("table");
        $output .= getCloseTag("form");
        return $output;
    }

    /**
     * Gets the buttons on the bottom of the task summary table
     */
    function getTaskSummaryButtonRow() {
        $output = "";
        $output .= ' <tr class ="fieldLabel">';
        //PRINCIPAL INVESTIGATOR
        if (strcmp(getUserRole(), "pi") === 0) {
            if (strcmp($this->projectStatus, "piReview") === 0 || strcmp($this->projectStatus, "submitComplete") === 0) {
                //if piReview no options
                $output .= ' <td colspan="8">Submitted to PI reviewer</td>';
            } else if (!isProjectInApprovedState($this->projectStatus)) {
                $output .= ' <td>';
                $output .= getFormInputElement("submit", "submit", NULL, "Edit Task");
                $output .= ' </td>';
                $output .= ' <td colspan="7">';
                $output .= getFormInputElement("submit", "submit", NULL, "Delete Task");
                $output .= ' </td>';
            } else if (strcmp($this->projectStatus, "piFeedback") === 0) {
                $output .= ' <td colspan="8">';
                $output .= getFormInputElement("submit", "submit", NULL, "Edit Task");
                $output .= ' </td>';
            } else if (strcmp($this->projectStatus, "approvalFinal") === 0) {
                $output .= ' <td colspan="1">';
                $output .= getFormInputElement("submit", "submit", NULL, "Change Status");
                $output .= ' </td>';
                $output .= ' <td colspan="1">';
                $output .= getDropDownMenu(getTaskStatusArray(), 'taskStatusDropdown', $this->status);
                $output .= ' </td>';
                $output .= ' <td colspan="6"></td>';
            } else {
                $output .= ' <td>';
                //echo getFormInputElement("submit", "submit", NULL, "Edit Task");
                $output .= ' </td>';
                $output .= ' <td colspan="7">';
                if (strcmp($this->projectStatus, "approved") === 0) {
                    if (strcmp($this->status, "inactive") === 0) {
                        $output .= getFormInputElement("submit", "submit", NULL, "Activate");
                    } else {
                        $output .= getFormInputElement("submit", "submit", NULL, "Deactivate");
                    }
                }
                $output .= ' </td>';
            }
        }
        //PRINCIPAL INVESTIGATOR REVIEWER
        if (strcmp(getUserRole(), "pireviewer") === 0) {
            if (strcmp($this->projectStatus, "submitComplete") === 0) {
                //if pi review then allow feedback
                $output .= ' <td colspan="1">';
                $output .= getHiddenField("wbsID", $this->wbsID);
                $output .= getFormInputElement("submit", "submit", NULL, "Add Notes");
                $output .= ' </td>';
                $output .= ' <td>' . getDropDownMenuText(getNotesTypeArray(), "notesTypeDropdown") . '</td>';
                $output .= ' <td colspan="7">';
                $output .= getFormInputElement("text", "textFieldNotes", "99%");
                $output .= ' </td>';
            } else if (strcmp($this->projectStatus, "piFeedback") === 0) {
                $output .= ' <td colspan="8">Awaiting feedback from PI</td>';
            } else if (strcmp($this->projectStatus, "piApproverSubmit") === 0) {
                $output .= ' <td colspan="8">Awaiting Approval from Approver</td>';
            }
        }
        $output .= '</tr>';
        return $output;
    }

    function getFinancialsCurrentYearTable() {
        //frog
        $financialTotals = new financialTotals();
        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<col width="7%"><col width="7%"><col width="7%"><col width="7%">';
        $output .= '<caption>Financials</caption>';
        $output .= commonModel::getFinancialTableHeader();
        foreach ($this->subtasks as $subtask) {
            $output .= ' <tr>';
            $bgColor = getStatusBackgroundColor($subtask->status, "task");
            $output .= $this->getTD("$subtask->percentComplete %", NULL, NULL, "rowspan='2'");
            $output .= "  <td bgcolor='$bgColor' class='border1' colspan='2' rowspan='2'>";
            $output .= "<b><a href=\"mainPage.php?request=subtask&action=viewSubtaskDetailsRequest&subtaskId=$subtask->ID\">";
            $output .= "$subtask->wbsString -- $subtask->title</a></b></td>";
            $actualCost = $subtask->financialObject->actualDollars;
            $actualHours = $subtask->financialObject->actualDuration;
            $proposedCost = $subtask->financialObject->curYearDollars;
            $proposedHours = $subtask->financialObject->curYearDuration;
            $output .= "  <td class='border1'>-</td><td class='border1'>-</td><td class='border1'>-</td><td class='border1'>-</td><td class='border1'>-</td><td class='border1'>-</td>";
            $output .= "<td class='border1'>P</td>";
            for ($i = 0; $i < 4; $i++) {
                $output .= "  <td class='border1'>$proposedHours[$i]</td>";
                $financialTotals->proposedHourTotal[$i] += $proposedHours[$i];
            }
            for ($i = 0; $i < 4; $i++) {
                $output .= "  <td class='border1'>$proposedCost[$i]</td>";
                $financialTotals->proposedDollarTotal[$i] +=$proposedCost[$i];
            }
            $output .= " <td class='border1'>-</td><td class='border1'>-</td>";
            $output .= ' </tr>';
            $output .= ' <tr class="grey">';
            $output .= ' <td>hrs</td><td>$</td>';
            $output .= '  <td>-</td><td>-</td><td>-</td><td>-</td>';

            $output .= "<td>A</td>";
            for ($i = 0; $i < 4; $i++) {
                $value = $actualHours[$i];
                $name = $subtask->projectID . ',' . $subtask->taskID . ',' . $subtask->ID . ',hours,' . $i;
                //$output .= " <input type='button' onclick=\"updateTaskFinancial(this)\" name='$name' id='hours$subtask->ID$i' value='$value'></input>";
                $output .= $this->getTD($value);
                $financialTotals->actualHourTotal[$i] += $actualHours[$i];
            }
            for ($i = 0; $i < 4; $i++) {
                $value = $actualCost[$i];
                $name = $subtask->projectID . ',' . $subtask->taskID . ',' . $subtask->ID . ',cost,' . $i;
                //$output .= "<td><div onclick=\"myFunction2(this)\" name='$name' id='cost$i' value='$value'>";
                //$output .= "<td><input type='button' onclick=\"updateTaskFinancial(this)\" name='$name' id='cost$subtask->ID$i' value='$value'></input>";
                //$output .= "</div></td>";
                $output .= $this->getTD($value);
                $financialTotals->actualDollarTotal[$i] += $actualCost[$i];
            }
            $output .= '  <td>-</td><td>-</td>';
            $output .= ' </tr>';
        }

        $output .= '<tr class="blue">';
        $output .= '<td colspan="3" rowspan="2">Totals</td><td class="border1">Proposed</td>';
        $output .= '  <td>-</td><td>-</td><td>-</td><td>-</td><td></td><td></td>';
        for ($i = 0; $i < 4; $i++) {
            $output .= '  <td>' . $financialTotals->proposedHourTotal[$i] . '</td>';
        }
        for ($i = 0; $i < 4; $i++) {
            $output .= '  <td>' . $financialTotals->proposedDollarTotal[$i] . '</td>';
        }
        $output .= " <td class='black'></td><td class='black'></td></tr>";
        $output .= '<tr class="blue">';
        $output .= '<td class="border1">Actual</td>';
        $output .= '  <td>-</td><td>-</td><td>-</td><td>-</td><td></td><td></td>';
        for ($i = 0; $i < 4; $i++) {
            $value = $financialTotals->actualHourTotal[$i];
            $id = "totalHour$i";
            $output .= '  <td id="' . $id . '">';
            $output .= $financialTotals->actualHourTotal[$i];
            $output .= "</td>";
        }
        for ($i = 0; $i < 4; $i++) {
            $id = "totalCost$i";
            $output .= '  <td id="' . $id . '">' . $financialTotals->actualDollarTotal[$i] . '</td>';
        }
        $output .= " <td></td><td></td>";
        $output .= '</tr>';
        $output .= ' </table>';
        return $output;
    }

    public function processChangeTaskStatus() {
        $newStatus = $_POST['taskStatusDropdown'];
        $taskId = $_GET['taskId'];
        $sqlInsert = "UPDATE task SET status='$newStatus' WHERE taskId=$taskId";
        $result = executeUpdate($sqlInsert);
        if ($result) {
            $url = $_SERVER['HTTP_REFERER'];
            return "location:$url";
        } else {
            return NULL;
        }
    }

    public function processDeleteTask() {
        $taskId = $_POST['taskID'];
        $projectId = $_POST['projectID'];
        executeDelete("DELETE FROM taskparammap WHERE taskId=$taskId");
        executeDelete("DELETE FROM taskreqmap WHERE taskId=$taskId");
        $result = executeDelete("DELETE FROM task WHERE taskId=$taskId");
        if ($result) {
            projectModelClass::updateNewProjectStatusFromOldStatic($projectId);
            return "location:mainPage.php?request=project&projectId=$projectId&action=viewProjectDetailsRequest&update=Task Deletion Successful";
        } else {
            return NULL;
        }
    }

    /**
     * Gets the html table of the fields related to the given task.
     * @param type $taskResult the fields related to this task
     * @param type $showLink false if single task, true if list of tasks
     */
    function getTaskDetailsTable($showLink) {

        $statusBGcolor = getStatusBackgroundColor($this->status, 'task');

        $output = "";
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<caption>Tasks</caption>';
        $output .= '<col width="5%">';
        $output .= ' <tr class ="header">';
        $output .= '     <td>WBS</td>';
        $output .= '     <td>Title</td>';
        $output .= '     <td>Description</td>';
        $output .= '     <td>Start date</td>';
        $output .= '     <td>End Date</td>';
        $output .= '     <td>Proposed Cost ($K)</td>';
        $output .= '     <td>Status</td>';
        $output .= ' </tr>';

        $output .= ' <tr class="field">';
        if ($showLink) {
            $output .= ' <td><a class="black" href="taskController.php?projectId=' . $this->projectID . '&taskId=' . $this->ID . '">' . $this->wbsString . '</a></td>';
        } else {
            $output .= ' <td>' . $this->wbsString . '</td>';
        }
        $output .= ' <td>' . $this->title . '</td>';
        $output .= ' <td>' . $this->description . '</td>';
        $output .= ' <td>' . $this->startDate . '</td>';
        $output .= ' <td>' . $this->endDate . '</td>';
        $output .= ' <td>' . $this->proposedCost . '</td>';
        $output .= " <td bgcolor = \"$statusBGcolor\">$this->status</td>";
        $output .= '      <input type="hidden" name="taskID" value="' . $this->ID . '">';
        $output .= ' </tr>';
        return $output;
    }

    public function getTaskSubtasks() {
        $array = array();
        $subtaskResult = executeSelect("SELECT * FROM subtask WHERE taskID=$this->ID");
        while ($row = mysqli_fetch_array($subtaskResult)) {
            $subtaskObj = new subtaskModelClass();
            $subtaskObj->init($row);
            array_push($array, $subtaskObj);
        }
        return $array;
    }

    function getTaskDetailsResult($taskID) {
        $sqlSelect = "SELECT * from task WHERE taskID=$taskID";
        return executeSelect($sqlSelect);
    }

    function getProjectDetailsForThisTask($taskID) {
        $sqlSelect = "SELECT p.projectID, p.startDate, p.endDate 
                      FROM project p, task t 
                      WHERE taskID=$taskID AND t.projectID=p.projectID";

        return executeSelect($sqlSelect);
    }

    function duplicateTask($newProjectID, $taskID) {
        $taskResult = executeSelect("SELECT * FROM task WHERE taskID=$taskID");
        while ($row = mysqli_fetch_array($ppResult)) {
            $personID = $row['personID'];
            $role = $row['role'];
            $insertResult = executeInsert("INSERT into projectpersonnel (personID, projectID, role)
                                                           VALUES ('$personID','$newProjectID','$role')");
            if (!$insertResult) {
                return false;
            }
        }
        return true;
    }

    function getTaskNotes($taskID, $type, $subtype = null, $value = NULL) {
        return executeSelect("SELECT n.* FROM notes n, task t WHERE t.taskID=$taskID AND t.wbsID=n.wbsId and type='$type'");
    }

    //function update
    static function updateTaskDuration($taskID) {
//query the cost for each subtask
        $sqlSelect = "SELECT duration FROM subtask WHERE taskID=$taskID";
        $result = executeSelect($sqlSelect);
        $taskDuration = 0;
        if ($result) {
//iterate through them and add them up
            while ($row = mysqli_fetch_assoc($result)) {
                $taskDuration += $row['duration'];
//echo $taskCost . '<br>';
            }
            $sqlUpdate = "UPDATE task SET duration=$taskDuration WHERE taskID=$taskID";
//echo $sqlUpdate . '<br>';
            return executeUpdate($sqlUpdate);
        } else {
            echo 'Error finding task ' . mysqli_error() . '<br>';
            return false;
        }
    }

    function updateTaskPOP($taskID, $startDateString, $endDateString) {
        $sqlSelect = "SELECT * FROM task WHERE taskID=$taskID";
        $result = executeSelect($sqlSelect);
        if ($result) {
            $row = mysqli_fetch_assoc($result);
            $taskStartDateString = $row['startDate'];
            $taskStartDate = strtotime($taskStartDateString);
            $taskEndDateString = $row['endDate'];
            $taskEndDate = strtotime($taskEndDateString);
            $startDate = strtotime($startDateString);
            $endDate = strtotime($endDateString);
            echo 'Dates: ' . $taskStartDateString . ' ' . $startDateString . ' ' . $taskEndDateString . ' ' . $endDateString . '<br>';
//do we need to update both
            if (( ($startDate < $taskStartDate) || strcmp($taskStartDateString, "0000-00-00") == 0 ) &&
                    ( ($endDate > $taskEndDate) || strcmp($taskEndDateString, "0000-00-00") == 0)) {
                $sqlUpdate = "UPDATE task SET startDate='$startDateString', endDate='$endDateString' WHERE taskID=$taskID";
                echo 'Both <br>';
                echo $sqlUpdate . '<br>';
                return executeInsert($sqlUpdate);
            }
//just update the start date
            else if ($startDate < $taskStartDate || strcmp($taskStartDateString, "0000-00-00") == 0) {
                $sqlUpdate = "UPDATE task SET startDate='$startDateString' WHERE taskID=$taskID";
                echo $sqlUpdate . '<br>';
                echo 'Start <br>';
                return executeInsert($sqlUpdate);
            }
//just update the end date
            else if ($endDate > $taskEndDate || strcmp($taskEndDateString, "0000-00-00") == 0) {
                $sqlUpdate = "UPDATE task SET  endDate='$endDateString' WHERE taskID=$taskID";
                echo $sqlUpdate . '<br>';
                echo 'End <br>';
                return executeInsert($sqlUpdate);
            }
//update none
            echo 'None <br>';
            return true;
        } else {
            echo 'Error finding task ' . $sqlSelect . '<br>';
            return false;
        }
    }

    static function updateTaskPOP2($taskID) {

//get the start/end dates for all subtasks
        $sqlSelect = "SELECT st.startDate AS subtaskStart, st.endDate AS subtaskEnd 
                  FROM subtask st 
                  WHERE st.taskID=$taskID";
        $result = executeSelect($sqlSelect);

//count rows what if someone removes the last subtask??
        if ($result && $result->num_rows > 0) {
            $row = mysqli_fetch_assoc($result);

            $minDateString = "2020-00-00";
            $maxDateString = "2000-00-00";
            $minDate = strtotime($minDateString);
            $maxDate = strtotime($maxDateString);
//echo $minDate . ' ' . $maxDate . '<br>';
//loop through each subtask and find the earliest and latest dates and set those as the task start/end dates
            do {
                $curStStartString = $row['subtaskStart'];
                $curStStart = strtotime($curStStartString);
                $curStEndString = $row['subtaskEnd'];
                $curStEnd = strtotime($curStEndString);
//echo $curStStart . ' ' . $curStEnd . '<br>';
                if ($curStStart < $minDate) {
                    $minDate = $curStStart;
                    $minDateString = $curStStartString;
                }
                if ($curStEnd > $maxDate) {
                    $maxDate = $curStEnd;
                    $maxDateString = $curStEndString;
                }
            } while ($row = mysqli_fetch_assoc($result));

            $sqlUpdate = "UPDATE task SET startDate='$minDateString', endDate='$maxDateString' WHERE taskID=$taskID";
            return executeUpdate($sqlUpdate);
        }
//this means this task no longer has any subtasks so let's set it back to the created state
        else {
            $sqlUpdate = "UPDATE task SET startDate='0000-00-00', endDate='0000-00-00', status='subtaskRequired' WHERE taskID=$taskID";
            return executeUpdate($sqlUpdate);
        }
    }

    function updateTaskStatusForGivenProject($projectId, $newStatus) {
        $taskIDResult = executeSelect("SELECT * FROM task WHERE $projectId=projectID");
        if ($taskIDResult) {
            while ($row = mysqli_fetch_array($taskIDResult)) {
                $taskID = $row['taskID'];
                $updateResult = executeUpdate("UPDATE task set status='$newStatus' WHERE taskID=$taskID");
                if ($updateResult) {
                    updateSubtaskStatusForGivenTask($taskID, $newStatus);
                } else {
                    return NULL;
                }
            }
        }
    }

    function updateAllSubtasksStatus($newStatus) {
        $subtasks = $this->getTaskSubtasks();
        for ($i = 0; $i < sizeof($subtasks); $i++) {
            $subtaskID = $subtasks[0]->ID;
            $updateResult = executeUpdate("UPDATE subtask set status='$newStatus' WHERE subtaskID=$subtaskID");
            if ($updateResult) {
                
            } else {
                return NULL;
            }
        }
    }

    function processNewSubtaskRequestQuarterly() {
        $subtaskModel = new subtaskModelClass();
        //subtask stuff
        $submissionType = $_POST['submissionType'];
        $taskID = $_POST['taskID'];
        $subtaskTitle = $_POST['titleTextField'];
        $subtaskDescription = $_POST['descriptionTextField'];

        $category = $_POST['dropdownCategory'];
        $deliverable = $_POST['deliverableTextField'];

        //edr stuff
        $param = $_POST['dropdownParameter'];
        $reqID = $_POST['reqDropdown'];

        //start/end
        $startDateDP = $_POST['startDateTextField'];
        $startDate = getMysqlDateFormat($startDateDP);
        $fy = getFYFromMysqlDateFormatStartDate($startDate);
        $endDateDP = $_POST['endDateTextField'];
        $endDate = getMysqlDateFormat($endDateDP);

        //labor stuff   
        $costArray = array();
        $hoursArray = array();
        for ($i = 1; $i < 5; $i++) {
            $subtaskLaborCost += $_POST['q' . $i . 'Cost'];
            $subtaskDuration += $_POST['q' . $i . 'Hours'];
            array_push($hoursArray, $_POST['q' . $i . 'Hours']);
            array_push($costArray, $_POST['q' . $i . 'Cost']);
        }
        //dependency stuff
        $dependencySubtasks = getgenericList("nameField", 20);
        $dependencyComments = getgenericList("commentsField", 20);

        //CREATE THE SUBTASK IN THE DATABASE
        //NEW
        if (strcasecmp($submissionType, "create") === 0) {
            //insert new wbs
            $nextWbs = getNextWbsAtThisLevel($this->wbsString);
            $wbsInsert = "INSERT into wbs (wbsString, description, other, level, fy) values ('$nextWbs', '$subtaskTitle','$subtaskDescription',3, $fy)";
            $wbsID = executeInsert($wbsInsert);
            //insert subtask
            $sqlInsert = "INSERT into subtask (taskID,title,description,duration,proposedCost,parameterID,reqId,startDate,endDate, status, wbsID, category, deliverable) VALUES 
                                      ('$taskID','$subtaskTitle','$subtaskDescription','$subtaskDuration',
                                       '$subtaskLaborCost','$param', '$reqID', '$startDate','$endDate', 'created', '$wbsID', '$category', '$deliverable')";
            //update the task status 
            updateStatus("active", "task", $taskID);
        }
        ////EDIT
        else {
            //do an update
            $subTaskID = $_POST['subtaskId'];
            $sqlInsert = "UPDATE subtask SET title='$subtaskTitle',description='$subtaskDescription',duration='$subtaskDuration',
                                             proposedCost='$subtaskLaborCost',parameterID='$param',reqId='$reqID',startDate='$startDate',
                                             endDate='$endDate', category='$category', deliverable='$deliverable' WHERE subtaskId=$subTaskID";
        }
        //the result of the insert or update
        $result = executeUpdate($sqlInsert);
        if ($result) {
            //subtask creation/update success 
            //get the subtaskID
            $sqlSelect = "SELECT subtaskId FROM subtask WHERE title='$subtaskTitle' AND description='$subtaskDescription' AND proposedCost='$subtaskLaborCost'";
            $result = executeSelect($sqlSelect);
            //echo $sqlSelect .'<br>';
            if ($result) {
                $row = mysqli_fetch_array($result);
                $subTaskId = $row['subtaskId'];

                //get the projectId
                $sqlSelect = "SELECT projectId FROM task WHERE taskId=$taskID";
                $result = executeSelect($sqlSelect);
                if ($result) {
                    $row = mysqli_fetch_array($result);
                    $projectId = $row['projectId'];
                    if ($subtaskModel->addDependenciesStatic($subTaskId, $dependencySubtasks, $dependencyComments)) {
                        //update the proposed cost/hours
                        if ($subtaskModel->updateSubtaskFinancialsRequestManual($subTaskId, $fy, $costArray, $hoursArray)) {
                            //return;
                            //update the cost of the related task
                            if ($this->updateTaskCost($taskID, "proposedCost")) {
                                //update the task POP
                                //if (updateTaskPOP($taskID, $startDate, $endDate)) {
                                if ($this->updateTaskPOP2($taskID)) {
                                    //return;
                                    //update task duration
                                    if ($this->updateTaskDuration($taskID)) {
                                        //update project status
                                        projectModelClass::updateNewProjectStatusFromOldStatic($projectId);

                                        //update the project cost
                                        if (!projectModelClass::updateProjectCostStatic($projectId, "proposedCost")) {
                                            echo 'error updating project cost <br>';
                                        } else {
                                            //project cost update success
                                            //echo "success";
                                            return "location:mainPage.php?request=task&action=viewTaskDetailsRequest&projectId=$projectId&taskId=$taskID&update=Subtask Created Successfully, add more below if needed";
                                            //return "location:mainPage.php?request=subtask&action=viewSubtaskDetailsRequest&subtaskId=$subTaskId";
                                            // header("location:taskController.php?projectId=$projectId&taskId=$taskID");
                                        }
                                    } else {
                                        echo 'error updating task Duration <br>';
                                    }
                                } else {
                                    echo 'error updating task POP <br>';
                                }
                            } else {
                                echo 'error updating task cost <br>';
                            }
                        } else {
                            echo 'Financial update failed <br>';
                        }
                    } else {
                        echo 'error with dependencies <br>';
                    }
                } else {
                    echo 'Select subtaskId failed <br>';
                }
            } else {
                echo 'Select projectId failed <br>';
            }
        } else {
            echo 'Insert subtaskId failed <br>';
        }
    }

    function processNewSubtaskRequest() {
        $subtaskModel = new subtaskModelClass();
        //subtask stuff
        $submissionType = $_POST['submissionType'];
        $taskID = $_POST['taskID'];
        $subtaskTitle = $_POST['titleTextField'];
        $subtaskDescription = $_POST['descriptionTextField'];
        $subtaskDuration = $_POST['durationTextField'];
        $category = $_POST['dropdownCategory'];
        $deliverable = $_POST['deliverableTextField'];
        $startDateDP = $_POST['startDateTextField'];
        $startDate = getMysqlDateFormat($startDateDP);
        $fy = getFYFromMysqlDateFormatStartDate($startDate);
        $endDateDP = $_POST['endDateTextField'];
        $endDate = getMysqlDateFormat($endDateDP);

        //edr stuff
        $param = $_POST['dropdownParameter'];
        //phase 1 sat/sensor are not required so fill in dummy value of 0
        if (isset($_POST['satDropdown'])) {
            $satellite = $_POST['satDropdown'];
            $sensor = $_POST['sensorDropdown'];
        } else {
            $satellite = 0;
            $sensor = 0;
        }
        $reqID = $_POST['reqDropdown'];

        //labor stuff    
        $subtaskLaborCost = 0;
        //new way
        if (isset($_POST['costTextField'])) {
            $subtaskLaborCost = $_POST['costTextField'];
        }
        //old way. Add up all of the individual performers costs
        else {
            $performers = array();
            $laborHours = array();
            $rates = array();
            for ($i = 0; $i < 10; $i++) {
                $nameField = 'nameField' . $i;
                //echo $nameField.'<br>';
                if (isset($_POST['' . $nameField . ''])) {
                    array_push($performers, $_POST['' . $nameField . '']);
                    //echo 'Name: ' . $_POST['' . $nameField . ''] . '<br>';
                    $hourField = 'hourField' . $i;
                    array_push($laborHours, $_POST['' . $hourField . '']);
                    //echo 'Hours: ' . $_POST['' . $hourField . ''] . '<br>';
                    $rateField = 'rateField' . $i;
                    array_push($rates, $_POST['' . $rateField . '']);
                    //echo 'Rate: ' . $_POST['' . $rateField . ''] . '<br>';
                    $subtaskLaborCost += $_POST['' . $hourField . ''] * $_POST['' . $rateField . ''];
                } else {
                    //break;
                }
            }
        }
        $subtaskLaborCost = round($subtaskLaborCost);
        $subtaskLaborHours = $_POST['durationTextField'];

        //return;
        //dependency stuff
        $dependencySubtasks = getgenericList("nameField", 20);
        $dependencyComments = getgenericList("commentsField", 20);

        //no EDR this spiral maybe implement down the road
//    if ($satellite == 0) {
//        $edrID = 0;
//    } else {
//        //retrieve the edrID for the selected edrDesription,sensor and sat
//        $sqlSelect = "SELECT edrID FROM edr, satsensormap map WHERE
//                      edr.parameterID='$param' AND
//                      edr.satSensorMapID=map.satSensorMapID AND
//                      map.satelliteID=$satellite AND
//                      map.sensorID=$sensor";
//        echo $sqlSelect;
//        $result = executeSelect($sqlSelect);
//        $row = mysqli_fetch_array($result);
//        $edrID = $row[0];
//    }
        //CREATE THE SUBTASK IN THE DATABASE
        //NEW
        if (strcasecmp($submissionType, "create") === 0) {

//            $taskWbsQuery = "SELECT wbsID FROM task WHERE taskId=$taskID";
//            $taskWbsResult = executeSelect($taskWbsQuery);
//            if ($taskWbsResult) {
//                $row = mysqli_fetch_array($taskWbsResult);
//                $taskWbs = getFieldGivenAnID("wbs", "wbsID", $row['wbsID'], "wbsString");
//                $nextWbs = getNextWbsAtThisLevel($taskWbs);
//            }
            //echo $this->wbsString;
            $nextWbs = getNextWbsAtThisLevel($this->wbsString);
            //echo ' ' . $nextWbs;
            //return;
            $wbsInsert = "INSERT into wbs (wbsString, description, other, level, fy) values ('$nextWbs', '$subtaskTitle','$subtaskDescription',3, $fy)";
            $wbsID = executeInsert($wbsInsert);
            //echo ' ' . $wbsID;
//            if (!$wbsResult) {
//                echo 'Duplicate WBS Go back and Change WBS ID Field<br> ' . $wbsInsert . '<br>';
//                return;
//            }
//            //get the wbsID we just created
//            $wbsResult = executeSelect("SELECT * FROM wbs WHERE wbsString='$nextWbs' && fy=$fy");
//            $row = mysqli_fetch_array($wbsResult);
            //$wbsID = $row['wbsID'];
            //create the subtask
            $sqlInsert = "INSERT into subtask (taskID,title,description,duration,proposedCost,parameterID,reqId,startDate,endDate, status, wbsID, category, deliverable) VALUES 
                                      ('$taskID','$subtaskTitle','$subtaskDescription','$subtaskDuration',
                                       '$subtaskLaborCost','$param', '$reqID', '$startDate','$endDate', 'created', '$wbsID', '$category', '$deliverable')";

            updateStatus("active", "task", $taskID);

            //set the planned financials
        }
        ////EDIT
        else {
            //do an update
            $subTaskID = $_POST['subtaskId'];
            $sqlInsert = "UPDATE subtask SET title='$subtaskTitle',description='$subtaskDescription',duration='$subtaskDuration',
                                             proposedCost='$subtaskLaborCost',parameterID='$param',reqId='$reqID',startDate='$startDate',
                                             endDate='$endDate', category='$category', deliverable='$deliverable' WHERE subtaskId=$subTaskID";
        }
        //echo $sqlInsert . '<br>';
        $result = executeUpdate($sqlInsert);
        if ($result) {
            //subtask creation success 
            //get the subtaskID
            $sqlSelect = "SELECT subtaskId FROM subtask WHERE title='$subtaskTitle' AND description='$subtaskDescription' AND proposedCost='$subtaskLaborCost'";
            $result = executeSelect($sqlSelect);
            //echo $sqlSelect .'<br>';
            if ($result) {
                $row = mysqli_fetch_array($result);
                $subTaskId = $row['subtaskId'];

                //get the projectId
                $sqlSelect = "SELECT projectId FROM task WHERE taskId=$taskID";
                $result = executeSelect($sqlSelect);
                if ($result) {
                    $row = mysqli_fetch_array($result);
                    $projectId = $row['projectId'];

                    //add the performers to this subtask
//                if (strcasecmp($submissionType, "edit") === 0) {
//                    //remove the old ones
//                    removePerformersFromSubtask($projectId, $subTaskId);
//                }
//                //echo "Add performers $subTaskId <br>";
//                addPerformersToSubTask($projectId, $subTaskId, $performers, $laborHours, $rates);
                    //add dependencies
                    if ($subtaskModel->addDependenciesStatic($subTaskId, $dependencySubtasks, $dependencyComments)) {
                        //update the proposed cost/hours
                        if ($subtaskModel->updateSubtaskProposedFinancialsStatic($subTaskId)) {
                            //return;
                            //update the cost of the related task
                            if ($this->updateTaskCost($taskID, "proposedCost")) {
                                //update the task POP
                                //if (updateTaskPOP($taskID, $startDate, $endDate)) {
                                if ($this->updateTaskPOP2($taskID)) {
                                    //return;
                                    //update task duration
                                    if ($this->updateTaskDuration($taskID)) {
                                        //update project status
                                        projectModelClass::updateNewProjectStatusFromOldStatic($projectId);

                                        //update the project cost
                                        if (!projectModelClass::updateProjectCostStatic($projectId, "proposedCost")) {
                                            echo 'error updating project cost <br>';
                                        } else {
                                            //project cost update success
                                            //echo "success";
                                            return "location:mainPage.php?request=task&action=viewTaskDetailsRequest&projectId=$projectId&taskId=$taskID&update=Subtask Created Successfully, add more below if needed";
                                            //return "location:mainPage.php?request=subtask&action=viewSubtaskDetailsRequest&subtaskId=$subTaskId";
                                            // header("location:taskController.php?projectId=$projectId&taskId=$taskID");
                                        }
                                    } else {
                                        echo 'error updating task Duration <br>';
                                    }
                                } else {
                                    echo 'error updating task POP <br>';
                                }
                            } else {
                                echo 'error updating task cost <br>';
                            }
                        } else {
                            echo 'Financial update failed <br>';
                        }
                    } else {
                        echo 'error with dependencies <br>';
                    }
                } else {
                    echo 'Select subtaskId failed <br>';
                }
            } else {
                echo 'Select projectId failed <br>';
            }
        } else {
            echo 'Insert subtaskId failed <br>';
        }
    }


}

?>
